﻿#region license
/*
 * Copyright (C) 2007 CchenSoft.com
 * 
 * See http://www.cchensoft.com/opensource/cc-portal/license.txt
 * 
 * Author: Billy Zhang
 * Email: billy_zh@126.com
 */
#endregion

using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Web;
using CchenSoft.Portal.Web.Controls;

namespace CchenSoft.Portal.Web
{
    [ToolboxData("<{0}:HtmlTextConfig runat=\"server\"> </{0}:HtmlTextConfig>")]
    public class HtmlTextConfigControl : ConfigControl
    {
        private Label titleLabel;
        private HtmlEditor editor;

        public string Title
        {
            get
            {
                EnsureChildControls();
                return titleLabel.Text;
            }
            set
            {
                EnsureChildControls();
                titleLabel.Text = value;
            }
        }

        public override string Text
        {
            get
            {
                EnsureChildControls();
                return editor.Content;
            }
            set
            {
                EnsureChildControls();
                editor.Content = value;
            }
        }

        protected override void RecreateChildControls()
        {
            EnsureChildControls();
        }

        protected override void CreateChildControls()
        {
            Controls.Clear();

            titleLabel = new Label();

            editor = new HtmlEditor();
            editor.ID = "editor";

            this.Controls.Add(titleLabel);
            this.Controls.Add(editor);
        }


        protected override void Render(HtmlTextWriter writer)
        {
            AddAttributesToRender(writer);

            writer.AddAttribute(
                HtmlTextWriterAttribute.Cellpadding,
                "1", false);
            titleLabel.RenderControl(writer);
            editor.RenderControl(writer);
        }

    }
}
